<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>

</html>
<script>
  console.log('这是一个主线程');
  var worker = new Worker('./worker.js');

  worker.postMessage('Hello World');
  worker.postMessage({
    method: 'echo',
    args: ['Work']
  });
  worker.onmessage = function (event) {
    console.log('Received message ' + event.data);
    doSomething();
  }

  function doSomething() {
    // 执行任务
    // worker.postMessage('Work done!');
  }
</script>